import 'package:boss/ui/page/takeoutManagement/constant/takeout_status.dart';
import 'package:json_annotation/json_annotation.dart';

import 'store_message.dart';

part 'takeout_order_list_data.g.dart';

@JsonSerializable()
class TakeoutOrderListData extends Object {
  @JsonKey(name: 'total')
  int total;

  @JsonKey(name: 'totalPage')
  int totalPage;

  @JsonKey(name: 'items', defaultValue: [])
  List<TakeoutOrderItem> items;

  TakeoutOrderListData(
    this.total,
    this.totalPage,
    this.items,
  );

  factory TakeoutOrderListData.fromJson(Map<String, dynamic> srcJson) => _$TakeoutOrderListDataFromJson(srcJson);

  Map<String, dynamic> toJson() => _$TakeoutOrderListDataToJson(this);
}

@JsonSerializable()
class TakeoutOrderItem extends Object with TakeoutStatus {
  @JsonKey(name: 'address')
  String address;

  @JsonKey(name: 'backDesc')
  String backDesc;

  @JsonKey(name: 'cancelDeliveryReason')
  String cancelDeliveryReason;

  @JsonKey(name: 'cancelType')
  int cancelType;

  @JsonKey(name: 'commodityActualFee')
  int commodityActualFee;

  @JsonKey(name: 'commodityAmount')
  int commodityAmount;

  @JsonKey(name: 'contactName')
  String contactName;

  @JsonKey(name: 'couponFee')
  int couponFee;

  @JsonKey(name: 'ctime')
  String ctime;

  @JsonKey(name: 'deliverFee')
  int deliverFee;

  @JsonKey(name: 'deliveryName')
  String deliveryName;

  @JsonKey(name: 'deliveryPhone')
  String deliveryPhone;

  @JsonKey(name: 'deliveryTime')
  String deliveryTime;

  @JsonKey(name: 'distance')
  int distance;

  @JsonKey(name: 'houseNum')
  String houseNum;

  @JsonKey(name: 'label')
  String label;

  @JsonKey(name: 'latitude')
  String latitude;

  @JsonKey(name: 'longitude')
  String longitude;

  @JsonKey(name: 'orderAmount')
  int orderAmount;

  @JsonKey(name: 'packFee')
  int packFee;

  @JsonKey(name: 'payType')
  int payType;

  @JsonKey(name: 'phoneNum')
  String phoneNum;

  @JsonKey(name: 'pickupCode')
  String pickupCode;

  @JsonKey(name: 'pickupTime')
  String pickupTime;

  @JsonKey(name: 'predictTime')
  String predictTime;

  @JsonKey(name: 'progress')
  String progress;

  @JsonKey(name: 'refundOrderPic')
  List<String> refundOrderPic;

  @JsonKey(name: 'refundOrderReason')
  String refundOrderReason;

  @JsonKey(name: 'rejectRefundReason')
  String rejectRefundReason;

  @JsonKey(name: 'remark')
  String remark;

  @JsonKey(name: 'sex')
  int sex;

  @JsonKey(name: 'store')
  StoreMessage store;

  @JsonKey(name: 'storeId')
  int storeId;

  @JsonKey(name: 'systemOrderStatus')
  int systemOrderStatus;

  @JsonKey(name: 'takeNo')
  int takeNo;

  @JsonKey(name: 'takeOutId')
  String takeOutId;

  @JsonKey(name: 'takeOutOrderDetails', defaultValue: [])
  List<TakeOutOrderDetails> takeOutOrderDetails;

  @JsonKey(name: 'takeOutStatus')
  int takeOutStatus;

  @JsonKey(name: 'tip')
  int tip;

  @JsonKey(name: 'totalAmount')
  int totalAmount;

  @JsonKey(name: 'totalFee')
  int totalFee;

  @JsonKey(name: 'type')
  int type;

  @JsonKey(name: 'unionOrderId')
  String unionOrderId;

  @JsonKey(name: 'userId')
  int userId;

  @JsonKey(name: 'utime')
  String utime;

  @JsonKey(name: 'orderDiscountType')
  String orderDiscountType;

  @JsonKey(name: 'refundAmount')
  int refundAmount;

  @JsonKey(name: 'refundMoneyOrder')
  RefundMoneyOrder refundMoneyOrder;

  String get sexText => (sex == 1 ? '(先生)' : sex == 2 ? '(女士)' : '');

  String get addressDetail => address + houseNum;

  TakeoutOrderItem(
      this.address,
      this.backDesc,
      this.cancelDeliveryReason,
      this.cancelType,
      this.commodityActualFee,
      this.commodityAmount,
      this.contactName,
      this.couponFee,
      this.ctime,
      this.deliverFee,
      this.deliveryName,
      this.deliveryPhone,
      this.deliveryTime,
      this.distance,
      this.houseNum,
      this.label,
      this.latitude,
      this.longitude,
      this.orderAmount,
      this.packFee,
      this.payType,
      this.phoneNum,
      this.pickupCode,
      this.pickupTime,
      this.predictTime,
      this.progress,
      this.refundOrderPic,
      this.refundOrderReason,
      this.rejectRefundReason,
      this.remark,
      this.sex,
      this.store,
      this.storeId,
      this.systemOrderStatus,
      this.takeNo,
      this.takeOutId,
      this.takeOutOrderDetails,
      this.takeOutStatus,
      this.tip,
      this.totalAmount,
      this.totalFee,
      this.type,
      this.unionOrderId,
      this.userId,
      this.utime,
      this.orderDiscountType);

  factory TakeoutOrderItem.fromJson(Map<String, dynamic> srcJson) => _$TakeoutOrderItemFromJson(srcJson);

  Map<String, dynamic> toJson() => _$TakeoutOrderItemToJson(this);
}

@JsonSerializable()
class TakeoutBusinessDTO extends Object {
  @JsonKey(name: 'businessStatus')
  int businessStatus;

  @JsonKey(name: 'settingId')
  int settingId;

  @JsonKey(name: 'storeId')
  int storeId;

  @JsonKey(name: 'takeoutBusinessHours')
  String takeoutBusinessHours;

  @JsonKey(name: 'takeoutSelfMention')
  int takeoutSelfMention;

  TakeoutBusinessDTO(
    this.businessStatus,
    this.settingId,
    this.storeId,
    this.takeoutBusinessHours,
    this.takeoutSelfMention,
  );

  factory TakeoutBusinessDTO.fromJson(Map<String, dynamic> srcJson) => _$TakeoutBusinessDTOFromJson(srcJson);

  Map<String, dynamic> toJson() => _$TakeoutBusinessDTOToJson(this);
}

@JsonSerializable()
class TakeOutOrderDetails extends Object {
  @JsonKey(name: 'actualFee')
  int actualFee;

  @JsonKey(name: 'commodityActualFee')
  int commodityActualFee;

  @JsonKey(name: 'commodityAmount')
  int commodityAmount;

  @JsonKey(name: 'commodityId')
  int commodityId;

  @JsonKey(name: 'commodityType')
  int commodityType;

  @JsonKey(name: 'ctime')
  String ctime;

  @JsonKey(name: 'description')
  String description;

  @JsonKey(name: 'discountId')
  int discountId;

  @JsonKey(name: 'discountName')
  String discountName;

  @JsonKey(name: 'discountNum')
  int discountNum;

  @JsonKey(name: 'discountType')
  int discountType;

  @JsonKey(name: 'headImage')
  String headImage;

  @JsonKey(name: 'id')
  int id;

  @JsonKey(name: 'image')
  String image;

  @JsonKey(name: 'memberPrice')
  int memberPrice;

  @JsonKey(name: 'nickname')
  String nickname;

  @JsonKey(name: 'num')
  int num;

  @JsonKey(name: 'packCartId')
  int packCartId;

  @JsonKey(name: 'price')
  int price;

  @JsonKey(name: 'remark')
  String remark;

  @JsonKey(name: 'secondType')
  int secondType;

  @JsonKey(name: 'skuId')
  int skuId;

  @JsonKey(name: 'skuName')
  String skuName;

  @JsonKey(name: 'specText')
  String specText;

  @JsonKey(name: 'storeId')
  int storeId;

  @JsonKey(name: 'takeOutId')
  String takeOutId;

  @JsonKey(name: 'takeOutOrderMeterials', defaultValue: [])
  List<TakeOutOrderMeterials> takeOutOrderMeterials;

  @JsonKey(name: 'takeOutOrderTastes', defaultValue: [])
  List<TakeOutOrderTastes> takeOutOrderTastes;

  @JsonKey(name: 'title')
  String title;

  @JsonKey(name: 'totalFee')
  int totalFee;

  @JsonKey(name: 'unit')
  String unit;

  @JsonKey(name: 'userId')
  int userId;

  @JsonKey(name: 'utime')
  String utime;

  @JsonKey(name: 'status')
  int status;

  @JsonKey(name: 'packFee')
  int packFee;

  String get titleWithSku => '$title${specText == null ? '' : "${(specText == '' || specText == null) ? '' : '(' + specText + ')'}"}';

  TakeOutOrderDetails(
      this.actualFee,
      this.commodityActualFee,
      this.commodityAmount,
      this.commodityId,
      this.commodityType,
      this.ctime,
      this.description,
      this.discountId,
      this.discountName,
      this.discountNum,
      this.discountType,
      this.headImage,
      this.id,
      this.image,
      this.memberPrice,
      this.nickname,
      this.num,
      this.packCartId,
      this.price,
      this.remark,
      this.secondType,
      this.skuId,
      this.skuName,
      this.specText,
      this.storeId,
      this.takeOutId,
      this.takeOutOrderMeterials,
      this.takeOutOrderTastes,
      this.title,
      this.totalFee,
      this.unit,
      this.userId,
      this.utime,
      this.packFee);

  factory TakeOutOrderDetails.fromJson(Map<String, dynamic> srcJson) => _$TakeOutOrderDetailsFromJson(srcJson);

  Map<String, dynamic> toJson() => _$TakeOutOrderDetailsToJson(this);
}

@JsonSerializable()
class TakeOutOrderMeterials extends Object {
  @JsonKey(name: 'id')
  int id;

  @JsonKey(name: 'meterialId')
  int meterialId;

  @JsonKey(name: 'meterialInitialAmount')
  int meterialInitialAmount;

  @JsonKey(name: 'meterialName')
  String meterialName;

  @JsonKey(name: 'meterialPrice')
  int meterialPrice;

  @JsonKey(name: 'orderDetailId')
  int orderDetailId;

  @JsonKey(name: 'unitNum')
  int unitNum;

  TakeOutOrderMeterials(
    this.id,
    this.meterialId,
    this.meterialInitialAmount,
    this.meterialName,
    this.meterialPrice,
    this.orderDetailId,
    this.unitNum,
  );

  factory TakeOutOrderMeterials.fromJson(Map<String, dynamic> srcJson) => _$TakeOutOrderMeterialsFromJson(srcJson);

  Map<String, dynamic> toJson() => _$TakeOutOrderMeterialsToJson(this);
}

@JsonSerializable()
class TakeOutOrderTastes extends Object {
  @JsonKey(name: 'id')
  int id;

  @JsonKey(name: 'orderDetailId')
  int orderDetailId;

  @JsonKey(name: 'tasteId')
  int tasteId;

  @JsonKey(name: 'tasteLabel')
  String tasteLabel;

  @JsonKey(name: 'tasteName')
  String tasteName;

  TakeOutOrderTastes(
    this.id,
    this.orderDetailId,
    this.tasteId,
    this.tasteLabel,
    this.tasteName,
  );

  factory TakeOutOrderTastes.fromJson(Map<String, dynamic> srcJson) => _$TakeOutOrderTastesFromJson(srcJson);

  Map<String, dynamic> toJson() => _$TakeOutOrderTastesToJson(this);
}

@JsonSerializable()
class RefundMoneyOrder extends Object {
  @JsonKey(name: 'refundId')
  String refundId;

  @JsonKey(name: 'storeId')
  int storeId;

  @JsonKey(name: 'userId')
  int userId;

  @JsonKey(name: 'phoneNum')
  String phoneNum;

  @JsonKey(name: 'contactName')
  String contactName;

  @JsonKey(name: 'rebackAmount')
  int rebackAmount;

  @JsonKey(name: 'takeOutId')
  String takeOutId;

  @JsonKey(name: 'type')
  int type;

  @JsonKey(name: 'status')
  int status;

  @JsonKey(name: 'backImage')
  String backImage;

  @JsonKey(name: 'backReason')
  String backReason;

  @JsonKey(name: 'rejectReason')
  String rejectReason;

  @JsonKey(name: 'ctime')
  String ctime;

  @JsonKey(name: 'utime')
  String utime;

  @JsonKey(name: 'refundProgess')
  String refundProgess;

  RefundMoneyOrder(
    this.refundId,
    this.storeId,
    this.userId,
    this.phoneNum,
    this.contactName,
    this.rebackAmount,
    this.takeOutId,
    this.type,
    this.status,
    this.backImage,
    this.backReason,
    this.rejectReason,
    this.ctime,
    this.utime,
    this.refundProgess,
  );

  factory RefundMoneyOrder.fromJson(Map<String, dynamic> srcJson) => _$RefundMoneyOrderFromJson(srcJson);

  Map<String, dynamic> toJson() => _$RefundMoneyOrderToJson(this);
}
